<?php
namespace app\common\model\agent;
use think\Model;

class PromotionBillModel extends Model
{
    // 表名
    protected $name = 'promotion_bill';
    // 表主键
    protected $pk = 'id';
    const TYPE = [
        ['value' => 1, 'label' => '佣金','code' => 'commission'],
        ['value' => 2, 'label' => '消费','code' => 'consumption'],
        ['value' => 3, 'label' => '提现','code' => 'withdrawal'],
        ['value' => 4, 'label' => '退款','code' => 'refund'],
    ];

    /**
     * 查询账单类型
     * @Author: 易军辉
     * @DateTime:2024-07-22 21:03
     * @param $key 编码或value
     * @param $type 1、查询value  2、查询名称 3、查询编码
     * @return mixed|void
     */
    public static  function getTypes($key,$type=1)
    {
        foreach (self::TYPE as $status) {
            if ($status['code'] == $key || $status['value'] == $key) {
                switch ($type) {
                    case 1:
                        return $status['value']; // 返回value
                    case 2:
                        return $status['label']; // 返回名称
                    case 3:
                        return $status['code']; // 返回code
                    default:
                        return $status['code']; // 未知类型，返回null
                }
            }
        }
    }
}
